package com.cuit.blogsystem.mapper;

import com.cuit.blogsystem.entity.Comment;
import com.cuit.blogsystem.entity.Text;
import com.cuit.blogsystem.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    /**
     * 用户登录
     */
    @Select("select * from user where username = #{userName}")
    User getByUserName(String userName);

    /**
     * 用户注册
     */
    void add(User user);

    /**
     * 用户上传文章
     */
    //@Insert("insert into text (user_id, content, create_time) values (#{userId}, #{content}, #{createTime})")
    void addText(Text text);

    /**
     * 上传用户文章关系表
     */
    @Insert("INSERT INTO user_text (user_id, text_id) values (#{userId}, #{id})")
    void setUserWithText(Text text);

    /**
     * 用户上传评论
     */
    @Insert("INSERT INTO comment (user_id, text_id, username, content, create_time) values (#{userId}, #{textId}, #{username}, #{content}, #{createTime})")
    void addComment(Comment comment);

    /**
     * 用户删除文章
     */
    @Delete("delete from text where id = #{textId}")
    void deleteText(Long textId);

    /**
     * 用户删除关联表
     */
    @Delete("delete from user_text where text_id = #{textId}")
    void deleteTextWithUser(Long textId);

    /**
     * 用户修改评论
     */
    void updateComment(Comment comment);

    /**
     * 用户修改文章
     */
    void updateText(Text text);

    /**
     * 用户删除评论
     */
    @Delete("delete from comment where id = #{id}")
    void deleteCommentById(Long id);

    /**
     * 查询用户名
     */
    @Select("select username from user where id = #{userId}")
    String findUsername(Long userId);

    /**
     * 用户信息
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getMyself(Long userId);

    /**
     * 删除分类
     */
    @Delete("delete from type where type_name = #{category}")
    void deleteType(String category);
}
